package vip.ola.code.ctrl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.ola.code.common.ctrl.BaseController;
import vip.ola.code.common.service.RpcCommonService;
import vip.ola.code.secruity.JwtUser;
import vip.ola.core.common.constant.CodeConstant;
import vip.ola.core.common.constant.Constant;
import vip.ola.core.common.domain.PayPageRes;
import vip.ola.core.entity.code.CodeOrder;

import java.util.List;

import static vip.ola.core.common.constant.CodeConstant.*;
import static vip.ola.core.common.constant.Constant.CODE_ROLE_NORMAL;

@RestController
@RequestMapping(Constant.CODE_CONTROLLER_ROOT_PATH + "/risk")
@PreAuthorize("hasRole('" + CODE_ROLE_NORMAL + "')")
public class RiskController extends BaseController {

    @Autowired
    private RpcCommonService rpcService;

    @RequestMapping("/list")
    public ResponseEntity<?> list() {
        JwtUser user = getUser();
        Long codeBusId = user.getCodeBusId();
        if(CODE_CODE_TYPE.equals(user.getType())){
            codeBusId = user.getId();
        }
        List<CodeOrder> list = rpcService.codeOrderService.getRiskOrderList(codeBusId);
        return ResponseEntity.ok(PayPageRes.buildSuccess(list, list.size()));
    }

}
